//
// Copyright (c) 2009 All Right Reserved
//
// Stephen Toub
// stoub@microsoft.com
// 2009-01-01
// Contains ...
using System;
using System.Globalization;
using System.IO;
using System.Text;
namespace LargoCommon.Midi {
/// A channel prefix meta event message.
[Serializable]
public sealed class MetaChannelPrefix : MetaEvent {
#region Fields
/// The meta id for this event.
private const byte EventMetaId = 0x20;
/// The prefix for the event.
private byte prefix;
#endregion
#region Constructors
/// Initializes a new instance of the MetaChannelPrefix class.
/// The amount of time before this event.
/// The prefix for the event.
public MetaChannelPrefix(long deltaTime, byte givenPrefix)
: base(deltaTime, EventMetaId) {
this.Prefix = givenPrefix;
}
#endregion
#region Properties
/// Gets or sets the prefix for the event.
/// General musical property.
private byte Prefix {
get => this.prefix;
set {
if (value > 0x7F) {
throw new ArgumentOutOfRangeException(nameof(value), value, "The prefix must be in the range from 0x0 to 0x7F.");
}
this.prefix = value;
}
}
#endregion
#region To String
/// Generate a string representation of the event.
/// A string representation of the event.
public override string ToString() {
var sb = new StringBuilder();
sb.Append(base.ToString());
sb.Append("\t");
sb.Append("0x");
sb.Append(this.Prefix.ToString("X2", CultureInfo.CurrentCulture.NumberFormat));
return sb.ToString();
}
#endregion
#region Methods
/// Write the event to the output stream.
/// The stream to which the event should be written.
public override void Write(Stream outputStream) {
if (outputStream == null) {
return;
}
//// Write out the base event information
base.Write(outputStream);
//// Event data
outputStream.WriteByte(0x01);
outputStream.WriteByte(this.prefix);
}
#endregion
}
}